package sunwin.yoms.service.third;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.dao.ThirdLandTypeDao;
import sunwin.yoms.domain.third.ThirdLandTypeDomain;

import java.util.List;

/**
 * Created by watson on 2015/9/10.
 */
@Service
public class ThirdLandTypeService {
    @Autowired
    private ThirdLandTypeDao thirdLandTypeDao;

    /**
     * 查找
     */
    public List<ThirdLandTypeDomain> findThirdLandType(ThirdLandTypeDomain thirdLandTypeDomain) throws YomsException {
        List<ThirdLandTypeDomain> domains = thirdLandTypeDao.getDomainCollection(thirdLandTypeDomain);
        if (domains.size() <= 0) {
            throw new YomsException("没有找到数据", 1);
        }
        return domains;
    }

    /**
     * 删除
     */
    public void delThirdLandType(int id) throws YomsException {
        ThirdLandTypeDomain domain = thirdLandTypeDao.getDomainById(id);
        if (domain == null) {
            throw new YomsException("非法请求");
        } else {
            if (thirdLandTypeDao.deleteDomain(domain) != 1) {
                throw new YomsException("删除失败");
            }
        }
    }
/**
 * 增加
 */
    public void addThirdLandType(ThirdLandTypeDomain thirdLandTypeDomain)throws YomsException{

        thirdLandTypeDao.addDomain(thirdLandTypeDomain);

    }
    /**
     * 更新
     */
   public void upThirdLandType(ThirdLandTypeDomain thirdLandTypeDomain)throws YomsException{
       ThirdLandTypeDomain domain=thirdLandTypeDao.getDomainById(thirdLandTypeDomain.getLandTypeId());
       if (domain==null){
           throw new YomsException("非法请求");
       }
       else {
           thirdLandTypeDao.updateDomain(domain);
       }
   }


}
